#-*- coding:utf-8 -*-
"""
Created on 2016-11-25
@author: bevin
"""

import os

import chardet
from jpype import *

dirname = os.path.dirname(__file__)
jarpath = os.path.join(dirname, 'jar/')
jarname = 'timereg.jar'

startJVM(getDefaultJVMPath(), r"-Djava.class.path=%s;%s" %
         (os.path.join(jarpath, jarname), jarpath), "-Xms1g", "-Xmx1g")
TimeReg = JClass('com.time.main.TimeReg')


def unify(func):
    def _deco(s):
        if not isinstance(s, unicode):
            code = chardet.detect(s)['encoding']
            s = s.decode(code)
        return func(s)
    return _deco


@unify
def parse(s):
    return eval(TimeReg.getTime(s))

if __name__ == '__main__':
    print parse(u"昨天下午五点整")
